/*
client_proc.dm
All of the procs required by the login system (short of saving/loading {see global/SQL_client_proc.dm})

Included:
	load_screen		load the default screen (new/load/delete)
	error			put an error message in the label on the default screen
	login			make the person log in, do all of the default stuff
*/

client/proc
	load_screen()
		winset(src,"create.load","is-disabled=true")
		winset(src,"create.delete","is-disabled=true")
		winset(src,"create.create","is-disabled=true")
		var
			DBI = "dbi:mysql:[sql_db]:[sql_ip]:[sql_port]"
			DBConnection/my_connection = new()
			connected = my_connection.Connect(DBI,sql_user,sql_pass)

		if(!connected)
			error("The MySQL server is currently down..")


		var/DBQuery/qry = my_connection.NewQuery("SELECT * FROM `[sql_table]` WHERE `ckey`='[ckey]';")
		qry.Execute()

		if(qry.RowCount() > 0)
			winset(src,"create.load","is-disabled=false")
			winset(src,"create.delete","is-disabled=false")
			winshow(src,"main",0)

		else
			winset(src,"create.create","is-disabled=false")
			winshow(src,"main",0)

		if(byond_version<world.byond_version)
			error("Your BYOND build ([byond_version]) is older; our server runs [world.byond_version]")

		winset(src,"create","pos=600,300")

	error(t)
		winset(src,"create.error","text=\"[t]\"")

	login(n)
		winshow_center(src,"main")
		winshow(src,"create",0)

		var
			DBI = "dbi:mysql:[sql_db]:[sql_ip]:[sql_port]"
			DBConnection/my_connection = new()
			connected = my_connection.Connect(DBI,sql_user,sql_pass)

		mob.name=n
		var/turf/t=pick(starts)
		mob.respawn="[t]"
		mob.icon_state="person"
		if(!connected)
			error("Sorry, it appears you cannot currently log in.")
			return

		var/DBQuery/qry_cr = my_connection.NewQuery(create_query(mob))
		qry_cr.Execute()

		mob.loc=locate(t)
		mob << "Welcome to the world, [mob.name]."
		mob.tx=mob.x
		mob.ty=mob.y
		mob.tz=mob.z
		char_screen=0
		spawn(20)
			var/mob/player/p = mob
			p.update_bars()
			p.create_hud()